package com.smooware.icms.adapter.list;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.smooware.icms.R;
import com.smooware.icms.data.model.WorkOrder;

public class SheduleListAdapter extends ArrayAdapter<WorkOrder> {

	public SheduleListAdapter(final Context context) {
		super(context, R.layout.shedule_list_row, R.id.wo_address,
				new ArrayList<WorkOrder>());
	}

	public SheduleListAdapter(final Context context,
			final List<WorkOrder> workOrders) {
		super(context, R.layout.shedule_list_row, R.id.wo_address, workOrders);
	}

	@Override
	public View getView(final int position, final View convertView,
			final ViewGroup parent) {
		View view = super.getView(position, convertView, parent);

		WorkOrder workOrder = getItem(position);

		initAddress(view, workOrder);
		initShortDescription(view, workOrder);
		initJobType(view, workOrder);
		initSheduleType(view, workOrder);
		initStatus(view, workOrder);

		return view;
	}

	private void initAddress(final View view, final WorkOrder workOrder) {
		TextView addressView = (TextView) view.findViewById(R.id.wo_address);
		addressView.setText(workOrder.getAddress());
	}

	private void initShortDescription(final View view, final WorkOrder workOrder) {
		TextView shortDescrView = (TextView) view
				.findViewById(R.id.wo_short_desc);
		shortDescrView.setText(workOrder.getShortDesription());
	}

	private void initJobType(final View view, final WorkOrder workOrder) {
		TextView jobTypeView = (TextView) view.findViewById(R.id.wo_job_type);
		jobTypeView.setText(workOrder.getJobType().getResID());
	}

	private void initSheduleType(final View view, final WorkOrder workOrder) {
		TextView sheduleTypeView = (TextView) view
				.findViewById(R.id.wo_shedule_type);
		sheduleTypeView.setText(workOrder.getSheduleType().getResID());
	}

	private void initStatus(final View view, final WorkOrder workOrder) {
		ImageView statusView = (ImageView) view.findViewById(R.id.wo_status);
		statusView.setImageResource(workOrder.getStatus().getResID());
	}
}
